#!/bin/bash

# 更新软件包
echo "更新软件包..."
dnf update -y

# 关闭防火墙
echo "关闭防火墙..."
systemctl stop firewalld
systemctl disable firewalld

# 关闭SELinux
echo "关闭SELinux..."
sed -i 's/enforcing/disabled/' /etc/selinux/config  # 永久
setenforce 0  # 临时

# 关闭swap
echo "关闭swap..."
sed -ri 's/.*swap.*/#&/' /etc/fstab    # 永久
swapoff -a  # 临时

# 配置sshd
echo "配置sshd..."
if [ "$#" -ge 1 ]; then
  ssh_port=$1
  sed -i 's/#Port 22/Port '$ssh_port'/g' /etc/ssh/sshd_config
fi
sed -i 's/#PermitRootLogin porhibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
systemctl restart sshd

# 安装必备软件
# dnf install vim sysstat net-tools gdisk telnet lrzsz -y
